/*
	Acron for acan
	www.abans.cn	abans@qq.com
	2010-10-08
*/

Acron = function(Did,objname){
	this.Did = Did;
	this.Jid = "#"+Did;
	this.objname = objname;
	var bobj = jQuery(".-body");
	if(bobj.find(".Acron").length==0){
		bobj.append(Ahtml.tag("div",{"class":"Acron"},
			Ahtml.tag("h2",{},'任务运行记录')
			+Ahtml.tag("p",{},'运行状态'+Ahtml.tag("span",{"class":"śtatus"}))
			+Ahtml.tag("textarea",{"class":"_log","readonly":"readonly"}))
		);
	}
}
Acron.prototype = new Acron();

Acron.run = function(url,time){
	if(!time){time=1;}
	var gdata = {};
	jQuery.ajax({
		async:false,
		type:"POST",url:url,data:"",
		beforeSend: function(){Acron.status('任务开始');},
		ajaxSend: function(){Acron.status('任务请求');},
		success: function(data){
			Acron.status('任务成功');
			gdata = data;
		},
		statusCode: {
			404: function() {Acron.status('执行任务失败');
			gdata.msg = '执行任务失败';}
		}
	});
	Acron.log(gdata.msg);
	if(gdata.time>0){
		time = gdata.time;
	}
	setTimeout("Acron.run('"+url+"',"+time+")",time);
}
Acron.status = function(str){
	jQuery("body .Acron .śtatus").text(str);
	return;
}
Acron.log = function(str){
	var cobj = jQuery("body .Acron ._log");
	var date = new Date();
	var datet = date.getFullYear()+"-"+date.getMonth()+1+"-"+date.getDate()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
	var old = cobj.val();
	if(old.split("\n").length>=100){
		old = old.split("\n").slice(0,-1).join("\n");
	}
	cobj.val("时间:"+datet+";结果:"+str+"\n"+old);
	return;
}
